package use_case.processRental;
import java.text.DateFormat;
import java.util.ArrayList;

import use_case.handlereturns.itemDescription;


public class Ledger {

	private ArrayList<Sale> saleList = new ArrayList<Sale>();
	private ArrayList<Customer> customerList = new ArrayList<Customer>();
	RentalStatistics rentalStatistics = new RentalStatistics( );
	
	public RentalStatistics getRentalStatistics() { return rentalStatistics; }
	
	public String[] getSales(){
		String[] list = new String[saleList.size()+1];
		//Title
		for (int i = 0; i < saleList.size(); i++) {
        	list[i] = customerList.get(i).getName()+"\t\t"+ String.format( "%.2f", saleList.get(i).getTotal()) +"\t"+customerList.get(i).getCardNumber()+"\t"+ 
		DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format( saleList.get(i).getDate().getTime());
        	//System.out.println(list[i+1]);
		}
		return list;
	}
	public int getNumberOfSales(){
		return saleList.size();
	}
	
	public int getNumberOfCustomers(){
		return customerList.size();
	}
	
	public void addSale(Sale s)
	{
		saleList.add(s);
		if( s != null && s.getCheckout() != null )
		{
			for( itemDescription iDescription : s.getCheckout().getCheckoutList())
				rentalStatistics.addSale(iDescription);
		}
	}
	
	public void addCustomer(Customer c){
		customerList.add(c);
	}
	
	public void displaySales()
	{
		System.out.println("_______________________");
		//System.out.println("\nSale Ledger Contains:\n" + "Customer" +"\t"+ "Amount" + "\t"+"Card Number"+ "\t"+ "Date");
		// Print Object content
		
        for (int i = 0; i < saleList.size(); i++) {
        	System.out.println(customerList.get(i).getName()+"\t\t"+ saleList.get(i).getTotal()+"\t"+customerList.get(i).getCardNumber()+"\t"+ saleList.get(i).getDate());
        }
	}
}
